import * as http from './utils/http'
import order from './order'
// let wxUrl = 'http://wx.xlink.cn'
let baseURL = 'http://42.121.122.23:8089'
// 获取url上的code参数
// function getSearchCode () {
//   let search = location.href
//   let searchs = {}
//   let strs
//   if (search.indexOf('?') !== -1) {
//     search = search.substr(search.indexOf('?') + 1)
//     strs = search.split('&')
//     for (let i = 0; i < strs.length; i++) {
//       searchs[strs[i].split('=')[0]] = decodeURIComponent(strs[i].split('=')[1])
//     }
//   }
//   window.localStorage.setItem('code', searchs['code'])
//   return searchs['code']
// }

/**
 * API统一入口
 *
 * 调用方式：
    import api from '../api'
    api.product.get(productId).then((res) => {
      // 请求状态
      console.log(res.status)
      // 请求头信息
      console.log(res.headers())
      // 赋值
      this.$set('someData', response.data)
    }, (res) => {
      // 失败回调
    })
 */

export default {
  order,
  jssdk (APPID, APPSECRET) {
    return http.get(
      `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${APPSECRET}`
    )
  },
  pay (deviceId, userId, balance) {
    return http.get(
      `${baseURL}/karcher/account_auth?device_id=${deviceId}&user_id=${userId}&balance=${balance}`
    )
  },

  getDeviceState (deviceId) {
    return http.get(
      `${baseURL}/karcher/status?device_id=${deviceId}`
    )
  }

}
